package thunderbirdgtd.entities;

import java.awt.Color;
import java.util.LinkedList;
import java.util.ListIterator;


public class Tag {
	private String tagName;
	private String tagDescription;
	private Color color;
	private int id;
	private boolean noColor = true;
	private static int id_tag = 0;
	
	public Tag(String tag, Color color){
		tagName = tag;
		this.color = color;
		noColor = color!=null ? false : true;
		this.id = id_tag++;
	}
	
	public Tag(String tag, Color color, int id){
		tagName = tag;
		this.color = color;
		noColor = color!=null ? false : true;
		this.id = id;
		if(id > id_tag)
			id_tag = id+1;
	}
	
	
	public Tag(String tag){
		this(tag, null);
		this.id = id_tag++;
	}
	
	public int getTagId(){
		return this.id;
	}

	public String getTagName() {
		return tagName;
	}

	public void setTagName(String tagName) {
		this.tagName = tagName;
	}

	public String getTagDescription() {
		return tagDescription;
	}

	public void setTagDescription(String tagDescription) {
		this.tagDescription = tagDescription;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}
	
	public boolean hasColor(){
		return !noColor;
	}
	
	public static Tag searchTagInLinkedList(String tagName, LinkedList<Tag> ll) throws Exception {
		if (ll == null)
			throw new Exception("null list");
		ListIterator<Tag> li = (ListIterator<Tag>) ll.listIterator();
		Tag tag = null;
		while(li.hasNext()){
			tag = li.next();
			if (tag.tagName.equals(tagName))
				return tag;
		}
		return null;
	}
	
	public String toString() {
		return "Name: " + tagName + " ID: " + id + " Color: " + color + " Description: " + tagDescription;
	}
}
